package interpreterPattern;

public class Main {

    public static void main(String[] args) {
        // 创建上下文并设置变量
        Context context = new Context();
        context.addVariable("x", 3);

        // 构建表达式：x + 5
        Expression variable = new VariableExpression("x");  //x：3
        Expression number = new NumberExpression(5);    //5
        Expression addExpression = new AddExpression(variable, number);

        // 解释并计算
        System.out.println("Result: " + addExpression.interpret(context));  // 输出：8

    }
}
